package main

import (
	"errors"
	"io/ioutil"
	"net/http"
	"strconv"
)

const userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0"

func RequestChannel(client *http.Client, channel *Channel) (b []byte, err error) {
	req, err := http.NewRequest("GET", channel.Url, nil)
	if err != nil {
		return
	}

	req.Header.Set("User-Agent", userAgent)

	resp, err := client.Do(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		err = errors.New("resp.StatusCode: " + strconv.Itoa(resp.StatusCode))
		return
	}

	return ioutil.ReadAll(resp.Body)
}
